﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Orderr;
using System.Collections.Generic;

namespace OrderServiceTest
{
    [TestClass]
    public class UnitTest1
    {

        String essi = "------------------------------\nOrder id = 234\nClient : TLM:\ntotal price = 2819\nDetails are below:\n单价为848的banana 3件\n单价为55的milk 5件\n";
        String ess = "------------------------------\nOrder id = 233\nClient : XB:\ntotal price = 5208\nDetails are below:\n单价为848的banana 3件\n单价为666的apple 4件\n";
        String esw = "------------------------------\nOrder id = 235\nClient : ZRZ:\ntotal price = 5246\nDetails are below:\n单价为848的banana 2件\n单价为55的milk 4件\n单价为666的apple 5件\n";
        [TestMethod]
        public void TestAdd()
        { 
            Good good1 = new Good("banana", 848);
            Good good2 = new Good("apple", 666);
            Good good3 = new Good("milk", 55);
            Client client1 = new Client("XB");
            Client client2 = new Client("TLM");
            Client client3 = new Client("ZRZ");
            Order list1 = new Order(233, client1, new List<OrderDetails>());
            list1.Details.Add(new OrderDetails(good1, 3));
            list1.Details.Add(new OrderDetails(good2, 4));

            OrderService master = new OrderService();
            master.add(list1);

            String a = master.QueryByOid(233);
            String b = "OID为233订单为：\n" + ess;
            Assert.AreEqual(b, a);
        }
        [TestMethod]
        public void TestDelete()
        {
            Good good1 = new Good("banana", 848);
            Good good2 = new Good("apple", 666);
            Good good3 = new Good("milk", 55);
            Client client1 = new Client("XB");
            Client client2 = new Client("TLM");
            Client client3 = new Client("ZRZ");
            Order list1 = new Order(233, client1, new List<OrderDetails>());
            list1.Details.Add(new OrderDetails(good1, 3));
            list1.Details.Add(new OrderDetails(good2, 4));
            Order list2 = new Order(234, client2, new List<OrderDetails>());
            list2.Details.Add(new OrderDetails(good1, 3));
            list2.Details.Add(new OrderDetails(good3, 5));
            Order list3 = new Order(235, client3, new List<OrderDetails>());
            list3.Details.Add(new OrderDetails(good1, 2));
            list3.Details.Add(new OrderDetails(good3, 4));
            list3.Details.Add(new OrderDetails(good2, 5));

            OrderService master = new OrderService();
            master.add(list1);
            master.add(list2);
            master.add(list3);

            master.delete(235);
            String a = master.QueryByPrice(0);
            Assert.AreEqual("订单金额大于等于0的有\n" + essi + ess, a);
        }
        [TestMethod]
        public void TestOID()
        {
            Good good1 = new Good("banana", 848);
            Good good2 = new Good("apple", 666);
            Good good3 = new Good("milk", 55);
            Client client1 = new Client("XB");
            Client client2 = new Client("TLM");
            Client client3 = new Client("ZRZ");
            Order list1 = new Order(233, client1, new List<OrderDetails>());
            list1.Details.Add(new OrderDetails(good1, 3));
            list1.Details.Add(new OrderDetails(good2, 4));
            Order list2 = new Order(234, client2, new List<OrderDetails>());
            list2.Details.Add(new OrderDetails(good1, 3));
            list2.Details.Add(new OrderDetails(good3, 5));
            Order list3 = new Order(235, client3, new List<OrderDetails>());
            list3.Details.Add(new OrderDetails(good1, 2));
            list3.Details.Add(new OrderDetails(good3, 4));
            list3.Details.Add(new OrderDetails(good2, 5));

            OrderService master = new OrderService();
            master.add(list1);
            master.add(list2);
            master.add(list3);

            String a = master.QueryByOid(234);
            Assert.AreEqual("OID为234订单为：\n" + essi, a);
        }
        [TestMethod]
        public void TestGOOD()
        {
            Good good1 = new Good("banana", 848);
            Good good2 = new Good("apple", 666);
            Good good3 = new Good("milk", 55);
            Client client1 = new Client("XB");
            Client client2 = new Client("TLM");
            Client client3 = new Client("ZRZ");
            Order list1 = new Order(233, client1, new List<OrderDetails>());
            list1.Details.Add(new OrderDetails(good1, 3));
            list1.Details.Add(new OrderDetails(good2, 4));
            Order list2 = new Order(234, client2, new List<OrderDetails>());
            list2.Details.Add(new OrderDetails(good1, 3));
            list2.Details.Add(new OrderDetails(good3, 5));
            Order list3 = new Order(235, client3, new List<OrderDetails>());
            list3.Details.Add(new OrderDetails(good1, 2));
            list3.Details.Add(new OrderDetails(good3, 4));
            list3.Details.Add(new OrderDetails(good2, 5));

            OrderService master = new OrderService();
            master.add(list1);
            master.add(list2);
            master.add(list3);

            String a = master.QueryByGood(good1);
            Assert.AreEqual("包含商品单价为848的banana的有\n" + essi + ess + esw, a);
        }
        [TestMethod]
        public void TestPrice()
        {
            Good good1 = new Good("banana", 848);
            Good good2 = new Good("apple", 666);
            Good good3 = new Good("milk", 55);
            Client client1 = new Client("XB");
            Client client2 = new Client("TLM");
            Client client3 = new Client("ZRZ");
            Order list1 = new Order(233, client1, new List<OrderDetails>());
            list1.Details.Add(new OrderDetails(good1, 3));
            list1.Details.Add(new OrderDetails(good2, 4));
            Order list2 = new Order(234, client2, new List<OrderDetails>());
            list2.Details.Add(new OrderDetails(good1, 3));
            list2.Details.Add(new OrderDetails(good3, 5));
            Order list3 = new Order(235, client3, new List<OrderDetails>());
            list3.Details.Add(new OrderDetails(good1, 2));
            list3.Details.Add(new OrderDetails(good3, 4));
            list3.Details.Add(new OrderDetails(good2, 5));

            OrderService master = new OrderService();
            master.add(list1);
            master.add(list2);
            master.add(list3);

            String a = master.QueryByPrice(5200);
            Assert.AreEqual("订单金额大于等于5200的有\n" + ess + esw, a);
        }
    }
}
